package com.jl.smartcard.ui.views.project;

import java.util.List;

import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;


public class ViewContentProvider implements IStructuredContentProvider,
		ITreeContentProvider {

	public ViewContentProvider() {
	}

	@Override
	public void inputChanged(Viewer v, Object oldInput, Object newInput) {
	}

	@Override
	public void dispose() {
	}

	@Override
	public Object[] getElements(Object inputElement) {
		if (inputElement instanceof List) {
			return ((List<?>) inputElement).toArray();
		} else if (inputElement instanceof TreeFolder) {
			return ((TreeFolder) inputElement).getChildren();
		} else {
			return new Object[0];
		}
	}

	@Override
	public Object getParent(Object child) {
		if (child instanceof TreeFile) {
			return ((TreeFile) child).getParent();
		}
		return null;
	}

	@Override
	public Object[] getChildren(Object parent) {
		if (parent instanceof TreeFolder) {
			return ((TreeFolder) parent).getChildren();
		}
		return new Object[0];
	}

	@Override
	public boolean hasChildren(Object parent) {
		if (parent instanceof TreeFolder)
			return ((TreeFolder) parent).hasChildren();
		return false;
	}
}
